
description = "header"
==
use Jason\Ccshop\Components\Catalog;
function onStart()
{ 
  //顶部通条的获取迁移到此处
  $bannerHeader = (new Catalog)->fetchAd('home-top-banner1');
  $this['bannerHeader'] = $bannerHeader;
  if($bannerHeader){
    $this['nowDate'] = date('Y-m-d H:i:s');
  }
  //dd($bannerHeader);
}
==
{% for item in catalog.fetchAd('home-top-banner1').items %}
	<a href="{{ item.link }}"><img src="{{ item.image.getPath() }}" alt="" width="100%"><span class="header-bannertext"></span></a>
{% endfor %}
{% for key,item in bannerHeader.items %}
<div id="bannerHeader_fromDate" style="display: none">{{ bannerHeader.from_date }}</div>
<div id="bannerHeader_toDate" style="display: none">{{ bannerHeader.to_date }}</div>
<div id="bannerHeader_now" style="display: none">{{ nowDate }}</div>
{% endfor %}

{% put scripts %}
<script type="text/javascript">
function buquan(num,length){
    var numstr = num.toString();
    var l=numstr.length;
    if (numstr.length>=length) {return numstr;}
      
    for(var  i = 0 ;i<length - l;i++){
      numstr = "0" + numstr;  
     }
    return numstr; 
}
    $(function(){
        clearInterval(timer);
        $("#bannerHeader_fromDate").hide();
        $("#bannerHeader_toDate").hide();
        $("#bannerHeader_now").hide();
        var endtime = $("#bannerHeader_toDate").eq(0).text().replace(/-/g, "/");
        endtime = new Date(endtime).getTime();
		var d=0;
		var h=0;
		var m=0;
		var s=0;
		function GetRTime(){
	        nowtime = new Date().getTime();
	        var chastart = endtime-nowtime;
	        t = chastart;
		    if(t>=0){
		      	d=Math.floor(t/1000/60/60/24);
		      	h=Math.floor(t/1000/60/60%24);
		      	m=Math.floor(t/1000/60%60);
		      	s=Math.floor(t/1000%60);
				/*ms=Math.floor(t%100)*/
				if(d<10 && d>=0) d=buquan(d,2);
				if(h<10 && h>=0) h=buquan(h,2);
				if(m<10 && m>=0) m=buquan(m,2);
				if(s<10 && s>=0) s=buquan(s,2);
				$('.header-bannertext').html("<ul><li><span>" + d + "</span></li>" + "<li><span>" + h + "</span></li>" + "<li><span>" + m + "</span></li>" + "<li><span>" + s + "</span></li>"+"</ul>");
		    } else {
				d=0;
				h=0;
				m=0;
				s=0;
				$('.header-bannertext').html("<ul><li><span>" + d + "</span></li>" + "<li><span>" + h + "</span></li>" + "<li><span>" + m + "</span></li>" + "<li><span>" + s + "</span></li>"+"</ul>");
        		clearInterval(timer);
			}
		}
		GetRTime();
  		var timer = setInterval(GetRTime,500);
    })
</script>
{% endput %}